#!/usr/bin/python
#
# Copyright (C) Nicola Bizzoca   2006/2007  <hannibal_smith@users.sourceforge.net>
# Copyright (C) Simone Economo   2006/2007  <ekoes@users.sourceforge.net>
# 
#	This file is part of Absynth-FTP.
#
#	Absynth-FTP is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 3 of the License, or
#	(at your option) any later version.
#
#	Absynth-FTP is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gconf

class Config:
	
	client_dir = "/apps/absynth-ftp/"
	
	def __init__(self):
		self.client = gconf.client_get_default()
		self.client.add_dir (self.client_dir, gconf.CLIENT_PRELOAD_NONE)
		self._setFunction = { bool : self.client.set_bool,
					    float : self.client.set_float,
					    int : self.client.set_int,
					    str : self.client.set_string}
		self._getFunction = {gconf.VALUE_BOOL : gconf.Value.get_bool,
							 gconf.VALUE_FLOAT : gconf.Value.get_float,
							 gconf.VALUE_INT : gconf.Value.get_int,
							 gconf.VALUE_STRING : gconf.Value.get_string}
		self.defaults = {"isFirstTime" : True,
						 "appName" : "Absynth FTP",
						 "appVersion" : "Alpha 1",
						 "showHidden" : False,
						 "welcomeTab" : True,}
		
	def get(self, name):
		entry = self.client.get(self.client_dir + name)
		if entry is None:
			try:
				return self.defaults[name]
			except KeyError:
				print 'No config value: ' + name
		function = self._getFunction[entry.type]
		return function(entry)
	
	def set(self, name, value):
		try:
			function = self._setFunction[type(value)]
		except KeyError:
			print 'Only config values of type: int, str, float, bool supported'
		function(self.client_dir + name, value)
		